package com.wing.member.model.request.validator;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wing.member.model.entity.MemberAuth;
import com.wing.member.service.MemberAuthService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 用户是否存在校验
 *
 * @author
 */
public class HasNotMemberAuthValidator implements ConstraintValidator<HasNotMemberAuth, Object> {

    @Autowired
    MemberAuthService memberAuthService;

    @Override
    public void initialize(HasNotMemberAuth constraintAnnotation) {
        //初始化的时候
        //System.out.println("my validator init");
    }

    @Override
    public boolean isValid(Object object, ConstraintValidatorContext constraintValidatorContext) {
        MemberAuth memberAuth = memberAuthService.getOne(new QueryWrapper<MemberAuth>().eq("identifier", object));
        if(memberAuth == null){
            return false;
        }
        //验证通过
        return true;
    }
}
